package com.xiaouyudeguang.common.utils;

import java.util.*;

public class CollectUtils {

    public static CollectUtils util = new CollectUtils() {};

    public static String EMPTY = "";

    public static List<?> EMPTY_LIST = new ArrayList<>();

    public static Set<?> EMPTY_SET = new HashSet<>();

    Map<?, ?> EMPTY_MAP = new HashMap<>();

    public static boolean isEmpty(String s) {
        return s == null || s.isEmpty();
    }

    public static boolean isNotEmpty(String s) {
        return !isEmpty(s);
    }

    public static boolean isBlank(String s) {
        return s == null || isEmpty(s.trim());
    }

    public static boolean isNotBlank(String s) {
        return !isBlank(s);
    }

    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }

    public static boolean isNotEmpty(Collection<?> collection) {
        return !isEmpty(collection);
    }

    public static boolean isEmpty(Map<?, ?> map) {
        return map == null || map.isEmpty();
    }

    public static boolean isNotEmpty(Map<?, ?> map) {
        return !isEmpty(map);
    }

    public static <E> List<E> emptyList() {
        return new ArrayList<>();
    }

    public static <K, V> Map<K, V> emptyMap() {
        return new HashMap<>();
    }

    public static <E> List<E> toList(E... es) {
        return Arrays.asList(es);
    }

    public static <E> Set<E> toSet(E... es) {
        return toSet(Arrays.asList(es));
    }

    public static <E> Set<E> toSet(List<E> list) {
        if (list == null) {
            return new HashSet<>();
        }
        return new HashSet<>(list);
    }

    public static <K, V> Map<K, V> toMap(K key, V value) {
        Map<K, V> map = new HashMap<>();
        map.put(key, value);
        return map;
    }

    public static <E> List<E> getOrDefault(List<E> list) {
        return getOrDefault(list, new ArrayList<>());
    }

    public static <E> List<E> getOrDefault(List<E> list, List<E> defaultValue) {
        return list == null ? defaultValue : list;
    }

    public static <K, V> Map<K, V> getOrDefault(Map<K, V> map) {
        return getOrDefault(map, new HashMap<>());
    }

    public static <K, V> Map<K, V> getOrDefault(Map<K, V> map, Map<K, V> defaultValue) {
        return map == null ? defaultValue : map;
    }
}
